using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;

namespace eliasen.eu.BizTalk.Functoids
{
    class StringReplace : BaseFunctoid
    {
        public StringReplace()
            : base()
        {
            //ID for this functoid
            this.ID = 6426;

            // resource assembly must be ProjectName.ResourceName if building with VS.Net
            SetupResourceAssembly(GetType().Namespace + "." + "eliasen.eu.BizTalk.Functoids.Resources", Assembly.GetExecutingAssembly());

            //Setup the Name, ToolTip, Help Description, and the Bitmap for this functoid
            SetName("Str_StringReplace_Name");
            SetTooltip("Str_StringReplace_Tooltip");
            SetDescription("Str_StringReplace_Description");
            SetBitmap("Bmp_StringReplace_Icon");

            this.SetMinParams(3);
            this.SetMaxParams(3);

            //set the function name that needs to be called when this Functoid is invoked. This means that
            //this Functoid assembly need to be present in GAC for its availability during Test..Map and Runtime.
            SetExternalFunctionName(GetType().Assembly.FullName, GetType().FullName, "GetReplacedString");

            //category for this functoid. This functoid goes under the String Functoid Tab in the
            //VS.Net toolbox for functoids.
            this.Category = FunctoidCategory.String;
            this.OutputConnectionType = ConnectionType.AllExceptRecord;

            AddInputConnectionType(ConnectionType.AllExceptRecord); //first input
            AddInputConnectionType(ConnectionType.AllExceptRecord); //second input
            AddInputConnectionType(ConnectionType.AllExceptRecord); //third input
        }

        //this is the function that gets called when the Map is executed which has this functoid.
        public string GetReplacedString(string str, string search, string replace)
        {
            if (String.IsNullOrEmpty(str))
                return String.Empty;
            if (search == null)
                return str;
            return str.Replace(search, replace);
        }
    }
}
